package com.uchedao.seller.ui.province_city;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.uchedao.seller.R;
import com.uchedao.seller.model.CityEntity;

import java.util.ArrayList;

/**
 * Created by ZhangZhanghua on 2015/10/29 0029.
 */
public class CityAdapter extends BaseAdapter {
    private ArrayList<CityEntity> mList;
    private Context mContext;
    private LayoutInflater inflater;
    private String provinceName;

    public CityAdapter(Context context,ArrayList<CityEntity> list, String provinceName){
        mList =list;
        mContext =context;
        inflater = LayoutInflater.from(mContext);
    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView ==null){
            convertView = inflater.inflate(R.layout.city_list_item,null);
            viewHolder = new ViewHolder();
            viewHolder.title = (TextView) convertView.findViewById(R.id.catalog);
            viewHolder.cityName = (TextView) convertView.findViewById(R.id.title);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (position == 0){
            viewHolder.title.setText("全部");
        }else if (position == 1){
            viewHolder.title.setText(provinceName);
        }else {
            viewHolder.title.setVisibility(View.GONE);
        }
        viewHolder.cityName.setText(mList.get(position).getName());

        return convertView;
    }
    private final class ViewHolder {
        TextView title;
        TextView cityName;
    }

}
